package com.secondGroup.interceptor;

import com.secondGroup.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * date 2022/5/5  15:41
 * Author: ws
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //查看session中是否有用户信息
        User userInfo = (User) request.getSession().getAttribute("userInfo");

        //没有登录登录 请求转发到 user/login
        if(userInfo==null){
            request.getRequestDispatcher("user/login");
            return false;
        }
        return true;
    }
}
